
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @module http.im
* @author: Hjava
* @description: HTTP模块IM请求
* @since: 2018-07-22 15:49:00
*/
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var http_core_1 = __webpack_require__(/*! _http/http.core */ "./src/core/http/http.core.ts");
var checkParams_1 = __webpack_require__(/*! _util/checkParams */ "./src/core/utils/checkParams.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var log_1 = __webpack_require__(/*! ./../utils/log */ "./src/core/utils/log.ts");
var http_vcard_1 = __webpack_require__(/*! _http/http.vcard */ "./src/core/http/http.vcard.ts");
exports.default = {
    /**
     * 获取单聊离线消息
     * @param options data{od|os|lm}
     */
    offline: function (options) {
        options.data.svid = 401;
        http_core_1.default._offline('/msg/api/chat/v1/offline/1v1', options, constant_1.LOG_FROM_SOURCE.CHAT);
    },
    /**
     * 获取群聊离线消息
     * @param options
     */
    offlineGroup: function (options) {
        options.data.svid = 401;
        http_core_1.default._offline('/msg/api/chat/v1/offline/group', options, constant_1.LOG_FROM_SOURCE.GROUP);
    },
    /**
     * 发送Read
     * @param read {}
     */
    readSync: function (options) {
        if (options.data.req) {
            options.data.req = options.data.req.getBase64();
        }
        http_core_1.default.request('/uinfo/api/v1/read/sync', options);
        //{'data':{'status':1},'rescode':0}
    },
    /**
     * 获取已读时间 read chats
     * @param read {}
     */
    chats: function (options) {
        var _suc = options.success;
        if (options.data && !options.data.ch) {
            options.data.ch = 0;
        }
        options.success = function (res) {
            if (res.rescode === 0) {
                res.data['sync_data'] = protocol_1.default.Response.fromBase64(res.data['sync_data']);
                res.data['sync_data2'] && (res.data['sync_data2'] = protocol_1.default.Response.fromBase64(res.data['sync_data2'], 2));
            }
            _suc(res);
        };
        http_core_1.default.request('/read/api/v2/list', options);
    },
    /**
     * 最近消息接口-根据时间获取会话列表接口,文档见: http://service.sankuai.com/#/services/com.sankuai.xm.xmnew.msgreader/docs/com.sankuai.xm.msg.read.web.controller.v3.MessageChatlistControllerV3_restful/com.sankuai.xm.msg.read.web.controller.v3.MessageChatlistControllerV3.getChatListByAppid(com.alibaba.fastjson.JSONObject%252C%2520javax.servlet.http.HttpServletRequest%252C%2520javax.servlet.http.HttpServletResponse)
     */
    chatlistByTime: function (options) {
        options.data.svid = 401;
        http_core_1.default._chatlist('/msg/api/chat/v3/chatlist/appid', options);
    },
    historyOfChannelByRange: function (options) {
        options.data.svid = 401;
        http_core_1.default._history('/msg/api/chat/v3/history/channel/range', options, options.data && options.data.bs && options.data.bs[0] && options.data.bs[0].g ? constant_1.LOG_FROM_SOURCE.GROUP : constant_1.LOG_FROM_SOURCE.CHAT);
    },
    historyReverseOfChannelByRange: function (options) {
        // historyReverseById是旧接口，功能不全，移动端目前使用的还是旧接口，historyReverseOfChannelByRange是新接口建议使用
        options.data.svid = 401;
        http_core_1.default._history('/msg/api/chat/v3/history/channel/reverse/range', options, options.data && options.data.bs && options.data.bs[0] && options.data.bs[0].g ? constant_1.LOG_FROM_SOURCE.GROUP : constant_1.LOG_FROM_SOURCE.CHAT);
    },
    historyReverseById: function (options) {
        options.data.svid = 401;
        http_core_1.default._history('/msg/api/chat/v1/history/reverse/byid', options, options.data && options.data.bs && options.data.bs[0] && options.data.bs[0].g ? constant_1.LOG_FROM_SOURCE.GROUP : constant_1.LOG_FROM_SOURCE.CHAT);
    },
    /**
     * 置顶会话列表
     */
    topChatlist: function (options) {
        var _suc = options.success;
        options.data.u = userData_1.default.get('uid');
        options.data.ai = userData_1.default.get('appId');
        options.success = function (res) {
            var data = res.data['res'];
            if (res.rescode === 0) {
                for (var i = 0; i < data.length; i++) {
                    try {
                        data[i] = protocol_1.default.Response.fromBase64(data[i]);
                    }
                    catch (e) {
                        if (i > 0) {
                            log_1.default.error('~~~~~ : topChatlist解析失败，上一条记录');
                            log_1.default.error(protocol_1.default.Response.fromBase64(data[i - 1]));
                        }
                        log_1.default.error('~~~~~topChatlist 解析失败，当前原始数据 info:' + e);
                        log_1.default.error(data[i]);
                    }
                }
            }
            _suc(res);
        };
        http_core_1.default.request('/fusion/message/v1/chat/favorite/get', options);
    },
    /**
     * 获取单条消息
     * @param read {}
     */
    single: function (options) {
        options.data.svid = 401;
        http_core_1.default._history('/msg/api/chat/v1/message/single', options, constant_1.LOG_FROM_SOURCE.CHAT);
    },
    /**
     * IM获取会话上一条非强制撤回消息
     * @param {id: 当前收到的强制撤回消息mid, bs: {b: 对方会话uid, g: 会话对方是否是群,是:1/否:0, jts: 加群时间，群会话参数}}
     */
    getPreviousMessage: function (options) {
        var _suc = options.success;
        options.data.u = userData_1.default.get('uid');
        options.data.ai = userData_1.default.get('appId');
        options.data.svid = 401;
        options.success = function (res) {
            var data = res.data['res'];
            if (res.rescode === 0) {
                for (var i = 0; i < data.length; i++) {
                    try {
                        data[i] = protocol_1.default.Response.fromBase64(data[i]);
                    }
                    catch (e) {
                        if (i > 0) {
                            log_1.default.error('~~~~~ : topChatlist解析失败，上一条记录');
                            log_1.default.error(protocol_1.default.Response.fromBase64(data[i - 1]));
                        }
                        log_1.default.error('~~~~~topChatlist 解析失败，当前原始数据 info:' + e);
                        log_1.default.error(data[i]);
                    }
                }
            }
            _suc(res);
        };
        http_core_1.default.request('/msg/api/chat/v3/message/previous', options);
    },
    /**
     * {data: {u, ul, category, name}}
     */
    createGroup: function (options) {
        http_core_1.default.request('/ginfo/api/v1/reg', options);
    },
    /**
     * {data:{g}}
     */
    fetchGroup: function (options) {
        http_vcard_1.default.fetchGroup(options);
    },
    /**
     * {data: {g}}
     */
    fetchGroupMembers: function (options) {
        http_core_1.default.request('/ginfo/api/v2/occupant/members', options);
    },
    /**
     * {data: {g, u}}
     */
    fetchGroupPermissions: function (options) {
        http_core_1.default.request('/ginfo/api/v1/getperm', options);
    },
    /**
     * {data: {u, gul=[]}}
     */
    fetchJoinTime: function (options) {
        http_core_1.default.request('/ginfo/api/v1/occupant/jointime', options);
    },
    /**
     * {data: {g, ul=[]}}
     */
    addGroupMembers: function (options) {
        http_core_1.default.request('/ginfo/api/v1/occupant/add', options);
    },
    /**
     * {data: {g, ul=[]}}
     */
    removeGroupMembers: function (options) {
        http_core_1.default.request('/ginfo/api/v1/occupant/remove', options);
    },
    /**
     * {data: {g, u, role}}
     */
    setGroupMemberRole: function (options) {
        http_core_1.default.request('/ginfo/api/v1/occupant/setrole', options);
    },
    /**
     * {data: {g, u}}
     */
    transferGroup: function (options) {
        http_core_1.default.request('/ginfo/api/v1/occupant/setowner', options);
    },
    /**
     * {data: {g, u}}
     */
    quitGroup: function (options) {
        http_core_1.default.request('/ginfo/api/v1/occupant/exit', options);
    },
    /**
     * 解散群组
     * {data: {g, u}}
     */
    dismissGroup: function (options) {
        http_core_1.default.request('ginfo/api/v1/del', options);
    },
    /**
     * 设置群组信息
     * {data: {g, u, in}}
     */
    setGroupInfo: function (options) {
        http_core_1.default.request('ginfo/api/v1/set', options);
    },
    /**
     * 获取群公告 https://km.sankuai.com/page/42305187
     * @param options {data: {gid}}
     */
    fetchGroupNotice: function (options) {
        http_core_1.default.request('/mtinfo/api/v1/groupAnnouncement/getIndex', options);
    },
    /**
     * 添加群公告 https://km.sankuai.com/page/42305187
     * @param options {data: {gid, content, atALl}}
     */
    addGroupNotice: function (options) {
        http_core_1.default.request('/mtinfo/api/v1/groupAnnouncement/add', options);
    },
    /**
     * 删除群公告 https://km.sankuai.com/page/42305187
     * @param options {data: {gid, gaid}}
     */
    removeGroupNotice: function (options) {
        http_core_1.default.request('/mtinfo/api/v1/groupAnnouncement/remove', options);
    },
    /**
     * 将群公告设置为已读 https://km.sankuai.com/page/42305187
     * @param options {data: {gid, gaid}}
     */
    readGroupNotice: function (options) {
        http_core_1.default.request('/mtinfo/api/v1/groupAnnouncement/read', options);
    },
    /**
     * 判断 CRUD 操作是否可行 https://km.sankuai.com/page/42305187
     * @param options {data: {gid, gaid, auth}}
     */
    getGroupNoticeAuth: function (options) {
        http_core_1.default.request('/mtinfo/api/v1/groupAnnouncement/canDoAuth', options);
    },
    /**
     * 获取群公告未读成员列表 https://km.sankuai.com/page/42305187
     * @param options {data: {gid, toOthers, toSelf}}
     */
    getGroupNoticeUnreadList: function (options) {
        http_core_1.default.request('/mtinfo/api/v1/groupAnnouncement/getUnreadUserList', options);
    },
    /**
     * 发送群系统消息 https://km.sankuai.com/page/42305187
     * @param options {data: {gid, toOthers, toSelf}}
     */
    sendGroupEventMessage: function (options) {
        http_core_1.default.request('/mtinfo/api/v1/groupAnnouncement/groupNotify', options);
    },
    /**
     * 设置群权限接口
     * {data: {g, perm}}
     */
    setGroupPermissions: function (options) {
        http_core_1.default.request('ginfo/api/v1/setperm', options);
    },
    /**
     * SDK租户可插拔配置接口,返回已经开启对端已读功能的业务ChannelId和svid类型
     */
    getOppositeConfig: function (options) {
        if (checkParams_1.default(options.data, ['tenant'])) {
            http_core_1.default.request('/msg/api/read/v1/config/tenant/opposite', options);
        }
    },
    /**
     * 获取和校验一个会话对端未读消息ID和己端未读消息ID
     */
    getBothOppositeUnreadMsg: function (options) {
        if (options && options.data && !options.data.svid) {
            options.data.svid = 401;
        }
        if (checkParams_1.default(options.data, ['buddy', 'svid', 'channel', 'smsgids', 'bmsgids'])) {
            http_core_1.default.request('/msg/api/read/v1/opposite/im/unread/bothchats', options);
        }
    },
    getChannelBothOppositeUnreadMsg: function (options) {
        if (options && options.data && !options.data.svid) {
            options.data.svid = 401;
        }
        if (checkParams_1.default(options.data, ['buddy', 'svid', 'channel', 'smsgids', 'bmsgids'])) {
            http_core_1.default.request('/msg/api/read/v1/opposite/im/unread/channel/bothchats', options);
        }
    },
    getUserVcard: function (options) {
        http_vcard_1.default.getUserVcard(options);
    },
    getGroupReceiptMessageList: function (options) {
        http_core_1.default.request('/receipt/api/v1/group/list', options);
    },
    getGroupReceiptMessageCount: function (options) {
        http_core_1.default.request('/receipt/api/v1/group/count', options);
    },
    getGroupReceiptConfig: function (options) {
        http_core_1.default.request('/receipt/api/v1/group/config', options);
    },
    getMessageAdditionConfig: function (options) {
        http_core_1.default.request('/msg/api/chat/v1/addition/config', options);
    },
    getIMMessageAddition: function (options) {
        http_core_1.default._messageAddition('/msg/api/chat/v1/addition/query', options, constant_1.LOG_FROM_SOURCE.CHAT);
    },
    getChatlistInfo: function (options) {
        http_core_1.default.request('/msg/api/chat/v3/chatlist/info', options);
    }
};


//# sourceURL=webpack://MTDX/./src/core/http/http.im.ts?